// import axios from "axios";
// var $http = axios.create({
//   timeout: 5000,
//   baseURL: "http://192.168.37.41:8989",
//   headers: { "Content-Type": "application/json" }
// });
import http from "../../http/index";
import api from "../../http/api";
export default {
  state: {
    isLoading: false,
    login: {
      password: "",
      username: ""
    },
    register: {
      usertype: "",
      username: "",
      userpwd: "",
      realname: "",
      sex: "",
      Idcard: "",
      tel: "",
      email: ""
    }
  },
  mutations: {
    updateLoadingStatus(state, payload) {
      state.isLoading = payload.isLoading;
    },
    handleRegister(state, payload) {
      state.register.usertype = payload.usertype;
      state.register.username = payload.username;
      state.register.userpwd = payload.userpwd;
      state.register.realname = payload.realname;
      state.register.sex = payload.sex;
      state.register.Idcard = payload.Idcard;
      state.register.tel = payload.tel;
      state.register.email = payload.email;
    },
    handleLogin(state, payload) {
      state.login.username = payload.loginName;
      state.login.password = payload.password;
    }
  },
  actions: {
    handleRegister({ commit }, params = {}) {
      console.log(api, "api");
      return http.allRequestPost(api.register, params, data => {
        console.log(params, 'params')
        commit("handleRegister", data);
      });
    },
    handleLogin({ commit }, params = {}) {
      return http.allRequestPost(api.login, params, data => {
        commit("handleLogin", data);
      });
    }
  }
};
